﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBAccess.Object;
using DBAccess.DAL;
using MySql.Data.MySqlClient;

namespace DBAccess.Business
{
    public class UserAccountBusiness
    {
        public static bool InsertUserAccount(UserAccount acc)
        {
            DatabaseClass db = new DatabaseClass();
            try
            {
                bool rs = false;
                string sql = "insert into useraccount(UserName,UserFacebook,PasswordUser,Hashkey,CreateDate,StatusUser) values(@username,@userfacebook,@password,@hashkey,@createDate,@status)";
                sql = "pro_CreateAccount";
                MySqlParameter[] pa = new MySqlParameter[6];
                //pa[0] = new MySqlParameter("@username", acc.UserName);
                //pa[1] = new MySqlParameter("@userfacebook", acc.UserFacebook);
                //pa[2] = new MySqlParameter("@password", acc.Password);
                //pa[3] = new MySqlParameter("@hashkey", acc.Hashkey);
                //pa[4] = new MySqlParameter("@createdate", acc.CreateDate);
                //pa[5] = new MySqlParameter("@status", acc.Status);

                pa[0] = new MySqlParameter("username", acc.UserName);
                pa[1] = new MySqlParameter("userfacebook", acc.UserFacebook);
                pa[2] = new MySqlParameter("pass", acc.Password);
                pa[3] = new MySqlParameter("hashkey", acc.Hashkey);
                pa[4] = new MySqlParameter("createdate", acc.CreateDate);
                pa[5] = new MySqlParameter("statususer", acc.Status);

                MySqlCommand command = db.GetCommand(sql, pa, true);
                int row = command.ExecuteNonQuery();
                if (row > 0)
                {
                    rs = true;
                }
                return rs;
            }
            catch (Exception ex)
            {
                return false;
            }
            finally
            {
                db.CloseData();
            }
        }

       
    }
}
